﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Server_NhaSach.DataAccess.HelperLayer;
using Server_NhaSach.DataTransferObject;
using System.Data.SqlClient;
using System.Data;

namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class PhieuChiDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
            set { _error = value; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertPhieuChi(PhieuChiDTO PChi)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[8];
            par[0] = new SqlParameter("@MaPC", PChi.MaPC);
            par[1] = new SqlParameter("@MaNCC", PChi.MaNCC);
            par[2] = new SqlParameter("@MaNV", PChi.MaNV);
            par[3] = new SqlParameter("@KhoanMucChi", PChi.KhoanMucChi);
            par[4] = new SqlParameter("@Lydochi", PChi.LyDoChi);
            par[5] = new SqlParameter("@NgayChi", PChi.NgayChi);
            par[6] = new SqlParameter("@Sotienchi", PChi.SoTienChi);
            par[7] = new SqlParameter("@SoChungTuPC", PChi.SoChungTuPC);

            try
            {
                helper.InsertQuery("sp_insert_phieuchi", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdatePhieuChi(PhieuChiDTO PChi)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[8];
            par[0] = new SqlParameter("@MaPC", PChi.MaPC);
            par[1] = new SqlParameter("@MaNCC", PChi.MaNCC);
            par[2] = new SqlParameter("@MaNV", PChi.MaNV);
            par[3] = new SqlParameter("@KhoanMucChi", PChi.KhoanMucChi);
            par[4] = new SqlParameter("@Lydochi", PChi.LyDoChi);
            par[5] = new SqlParameter("@NgayChi", PChi.NgayChi);
            par[6] = new SqlParameter("@Sotienchi", PChi.SoTienChi);
            par[7] = new SqlParameter("@SoChungTuPC", PChi.SoChungTuPC);
            try
            {
                helper.UpdateQuery("sp_update_phieuchi", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeletePhieuChi(string MaPC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@MaPC", MaPC);
            try
            {
                helper.DeleteQuery("sp_delete_phieuchi", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_PC()
        {
            helper = new Helper();
            DataSet ds_phieuchi = helper.SelectQuery("sp_layds_phieuchi");
            return ds_phieuchi;
        }
        #endregion
    }
}